package neusoft.yuejian_11.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;

import neusoft.yuejian_11.adapter.InforListAdapter;
import neusoft.yuejian_11.base.BaseActivity;
import neusoft.yuejian_11.bean.InformBean;
import neusoft.yuejian_11.fragment.SpaceItemDecoration;
import neusoft.yuejian_11.listener.RetrofitListener;
import neusoft.yuejian_11.model.UserModel;
import neusoft.yuejian_11.R;

import java.util.List;

//系统通知（已改）
public class InforActivity extends BaseActivity  implements RetrofitListener {
    private RecyclerView recyclerView;
    private InforListAdapter adapter;
    private TextView adminbutton;
    private  TextView  jlbbutton;
    private ImageButton imageButtonBack;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_infor);
        initView();
        initData();

        //返回前一页
        imageButtonBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

        adminbutton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent =new Intent(InforActivity.this,InforActivity.class);
                startActivityForResult(intent,1 );//requestCode
            }
        });
        jlbbutton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent =new Intent(InforActivity.this,ClubInformActivity.class);
                startActivityForResult(intent,1 );//requestCode
            }
        });
    }

    private void initData() {
        UserModel userModel = new UserModel();
        userModel.getInformlist(this);
    }


    private void initView() {
        recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
        adminbutton= (TextView) findViewById(R.id.adminbutton);
        jlbbutton= (TextView) findViewById(R.id.clubbutton);
        imageButtonBack = (ImageButton) findViewById(R.id.imageButtom_back);
    }

    @Override
    public void onSuccess(Object o, int flag) {
        List<InformBean> informBean=(List<InformBean>)o;
        adapter = new InforListAdapter(InforActivity.this, informBean);
        LinearLayoutManager layoutManager = new LinearLayoutManager(InforActivity.this);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setAdapter(adapter);
        recyclerView.addItemDecoration(new SpaceItemDecoration(4));
        recyclerView.setItemAnimator(new DefaultItemAnimator());
    }

    @Override
    public void onFail() {

    }

}
